//
//  XJCTimeTableViewCell.m
//  On The Load
//
//  Created by 许嘉成 on 15/11/6.
//  Copyright © 2015年 @@叶一闽. All rights reserved.
//

#import "XJCTimeTableViewCell.h"
#import <UIImageView+WebCache.h>
#import "VideoModel.h"

@interface XJCTimeTableViewCell ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *descLabel;

@end

@implementation XJCTimeTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
                [self createCell];
    }
    return self;
}
- (void)createCell{
    self.picImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 200*SCALEH)];
    [self.picImg setBackgroundColor:[UIColor redColor]];
    [self.contentView addSubview:self.picImg];
    
//    UIImageView *backImg = [[UIImageView alloc]initWithFrame:self.picImg.frame];
//    backImg.image = [UIImage imageNamed:@"shadow.png"];
//    backImg.alpha = 0.9;
//    [self.picImg addSubview:backImg];
    
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 80*SCALEH, WIDTH, 30*SCALEH)];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:18];
    self.titleLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.titleLabel];

    self.descLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.titleLabel.frame.origin.y+self.titleLabel.frame.size.height+8*SCALEH, WIDTH, 20*SCALEH)];
    self.descLabel.font = [UIFont systemFontOfSize:13];
    self.descLabel.textColor = [UIColor whiteColor];
    self.descLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.descLabel];
    
}
- (void)setVideoModel:(XJCVideoModel *)videoModel{
    _videoModel = videoModel;
    [self.picImg sd_setImageWithURL:[NSURL URLWithString:_videoModel.coverForDetail] placeholderImage:PLACEHOLDER];
    self.titleLabel.text = _videoModel.title;
    
    /***字符串拼接****/
    NSString *str1 = @"#";
    NSString *str2 = [str1 stringByAppendingString:@"旅行  /  "];
    int x =  [_videoModel.duration intValue];
    NSLog(@"@%@",_videoModel.duration);
    NSString *str3 = [NSString stringWithFormat:@"%d",x/60];
    NSLog(@"!%d",x);
    NSString *str4 = [NSString stringWithFormat:@"%d",x%60];
    if (x/60 >= 10) {
        if (x % 60 >= 10) {
            NSString *str5 = [[[[str2 stringByAppendingString:str3]stringByAppendingString:@"'"]stringByAppendingString:str4]stringByAppendingString:@"''"];
            self.descLabel.text = str5;
        }else{
            NSString *str5 = [[[[[str2 stringByAppendingString:str3]stringByAppendingString:@"'"] stringByAppendingString:@"0"]stringByAppendingString:str4]stringByAppendingString:@"''"];
            self.descLabel.text = str5;
        }
        
    }else{
        if (x % 60 >= 10) {
            NSString *str5 = [[[[[str2 stringByAppendingString:@"0"] stringByAppendingString:str3]stringByAppendingString:@"'"]stringByAppendingString:str4]stringByAppendingString:@"''"];
            self.descLabel.text = str5;
        }else{
            NSString *str5 = [[[[[[str2 stringByAppendingString:@"0"] stringByAppendingString:str3]stringByAppendingString:@"'"] stringByAppendingString:@"0"]stringByAppendingString:str4]stringByAppendingString:@"''"];
            self.descLabel.text = str5;
        }
        
    }
    
    
}

- (void)setModel:(VideoModel *)model{
    
    _model = model;
    [self.picImg sd_setImageWithURL:[NSURL URLWithString:model.coverForFeed] placeholderImage:PLACEHOLDER];
    self.titleLabel.text = model.title;
    
    /***字符串拼接****/
    NSString *str1 = @"#";
    NSString *str2 = [str1 stringByAppendingString:@"旅行  /  "];
    int x =  [model.date intValue];
    NSLog(@"@%@",_videoModel.duration);
    NSString *str3 = [NSString stringWithFormat:@"%d",x/60];
    NSLog(@"!%d",x);
    NSString *str4 = [NSString stringWithFormat:@"%d",x%60];
    if (x/60 >= 10) {
        if (x % 60 >= 10) {
            NSString *str5 = [[[[str2 stringByAppendingString:str3]stringByAppendingString:@"'"]stringByAppendingString:str4]stringByAppendingString:@"''"];
            self.descLabel.text = str5;
        }else{
            NSString *str5 = [[[[[str2 stringByAppendingString:str3]stringByAppendingString:@"'"] stringByAppendingString:@"0"]stringByAppendingString:str4]stringByAppendingString:@"''"];
            self.descLabel.text = str5;
        }
        
    }else{
        if (x % 60 >= 10) {
            NSString *str5 = [[[[[str2 stringByAppendingString:@"0"] stringByAppendingString:str3]stringByAppendingString:@"'"]stringByAppendingString:str4]stringByAppendingString:@"''"];
            self.descLabel.text = str5;
        }else{
            NSString *str5 = [[[[[[str2 stringByAppendingString:@"0"] stringByAppendingString:str3]stringByAppendingString:@"'"] stringByAppendingString:@"0"]stringByAppendingString:str4]stringByAppendingString:@"''"];
            self.descLabel.text = str5;
        }
        
    }
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
